import random

# 精美的界面完成
print("************************************")
print("|           中国工商银行            |")
print("|            V1.0                  |")
print("************************************")
print("|            1、开户               |")
print("|            2、存钱               |")
print("|            3、取钱               |")
print("|            4、转账               |")
print("|            5、查询               |")
print("|            6、再见               |")
print("***********************************")
bank = {}  # 空字典
# bank={78913791: {'username': 'Frank', 'password': '123456', 'country': '俄罗斯', 'province': '乌克兰', 'street': '基辅', 'door': '001', 'bank_name': '北京市昌平区沙河镇老牛湾车站沙阳路中国工商银行分行街道办支行银行', 'money': 0}}
bank_name = "中国工商银行昌平支行"


# 全局变量
def user_info():
    account = random.randint(10000000, 99999999)
    username = input("请输入您的用户名")
    password = input("请输入您的密码")
    country = input("\t\t请输入您的国家")
    province = input("\t\t请输入您的省份")
    street = input("\t\t请输入您的街道")
    door = input("\t\t请输入您的门牌号")
    x = addbank(account, username, password, country, province, street, door)
    if x == 1:
        print("添加用户成功，以下是您的信息")
        info = '''
        ------------%s-----------
                                    账号：%s
                                    用户名:%s
                                    密码：********
                                    国家：%s
                                    省份：%s
                                    街道：%s
                                    门牌号：%s
                                    余额：%s
        '''
        print(info % (bank_name, account, username, country, province, street, door, bank[account]['money']))
    elif x == 2:
        print("账号重复")
    elif x == 3:
        print("数据库满")


def addbank(account, username, password, country, province, street, door):
    if len(bank) >= 100:
        return 3
    elif account in bank.keys():
        return 2
    else:
        bank[account] = {
            "username": username,
            "password": password,
            "country": country,
            "province": province,
            "street": street,
            "door": door,
            "bank_name": bank_name,
            "money": 0
        }
        return 1


def Deposit_money():
    while True:
        account = input("请输入你的账号")
        if account.isdigit():
            account = int(account)
            break
        else:
            print("请重新输入")
    while True:
        money1 = input("请输入存储金额")
        if money1.isdigit():
            money1 = int(money1)
            break
        else:
            print("请重新输入")
    global bank
    if account in bank:
        bank[account]["money"] = bank[account]["money"] + money1
        print("用户", bank[account]["username"], "您好，你目前的余额为", bank[account]["money"])
    else:
        return False


def Withdraw_money():
    while True:
        account = input("请输入你的账号")
        money1 = input("请输入取出金额")
        if account.isdigit():
            account = int(account)
        if money1.isdigit():
            money1 = int(money1)
            break
        else:
            print("请重新输入")
    password = input("请输入你的密码")
    if account in bank:
        if bank[account]["password"] == password:
            if bank[account]["money"] < money1:
                return 1
            else:
                bank[account]["money"] = bank[account]["money"] - money1
                print("用户", bank[account]["username"], "您好，你目前的余额为", bank[account]["money"])
        else:
            return 2
    else:
        return 3


def transfer_money():
    while True:
        account = input("请输入你的账号")
        account1 = input("请输入转账账号")
        money2 = input("请输入转出金额")
        if account.isdigit():
            account = int(account)
        if money2.isdigit():
            money2 = int(money2)
            break
        else:
            print("请重新输入")
    password = input("请输入你的密码")
    if account in bank:
        if bank[account]["password"] == password:
            if bank[account]["money"] < money2:
                return 1
            else:
                bank[account]["money"] = bank[account]["money"] - money2
                bank[account1]["money"] = bank[account1]["money"] + money2
                print("转账成功")
        else:
            return 2
    else:
        return 3


def query():
    global bank
    while True:
        account = input("请输入要查询的账号")
        if account.isdigit():
            account = int(account)
            break
        else:
            print("请输入正确的账号")
    password = input("请输入密码")
    if account in bank:
        if bank[account]["password"] == password:
            print("账户信息：")
            info = '''
                   ------------%s-----------
                                               账号：%s
                                               用户名:%s
                                               密码：********
                                               国家：%s
                                               省份：%s
                                               街道：%s
                                               门牌号：%s
                                               余额：%s
                   '''
            print(info % (bank[account]["username"], account, bank[account]["country"], bank[account]["province"],
                          bank[account]["street"], bank[account]["door"], bank[account]['money'],
                          bank[account]["bank_name"]))
        else:
            print("密码错误")
    else:
        print("账户不存在")


while True:
    op = input("请选择业务")
    if op == "1":
        print("开户")
        user_info()
    elif op == "2":
        print("存钱")
        Deposit_money()
    elif op == "3":
        print("取钱")
        x = Withdraw_money()
        if x == 1:
            print("余额不足")
        elif x == 2:
            print("密码错误")
        elif x == 3:
            print("账号不存在")
        Withdraw_money()
    elif op == "4":
        print("转账")
        y = transfer_money()
        if y == 1:
            print("余额不足")
        elif y == 2:
            print("密码错误")
        elif y == 3:
            print("账号不存在")
        transfer_money()
    elif op == "5":
        print("查询账户")
        query()
    elif op == "6":
        print("欢迎下次使用")
        break
    else:
        print("请正确输入")
